import csv
import json

sFileName = 'D:\\workspace\\Novel-Coronavirus-Updates\\1.csv'

extra_arr = ['省份', '美国', '柬埔寨', '芬兰', '斯里兰卡', '瑞典', '越南',
             '加拿大', '印度', '阿联酋', '泰国', '日本', '西班牙', "比利时",
             '马来西亚',
             '意大利',
             '尼泊尔',
             '俄罗斯',
             '菲律宾',
             '德国',
             '澳大利亚',
             '新加坡',
             '法国',
             '韩国',
             '英国']

provinces = []

result = {}

with open(sFileName, newline='', encoding='UTF-8') as csvfile:
    rows = csv.reader(csvfile)
    for row in rows:
        if row[1] not in extra_arr:
            provinces.append(row[1])

provinces = set(provinces)

for province in provinces:
    data = {}
    with open(sFileName, newline='', encoding='UTF-8') as csvfile:
        rows = csv.reader(csvfile)
        for row in rows:
            if row[1] == province:
                key = row[0].replace('月', '-')
                key = key.replace('日', '')
                temp = key.split('-')
                month = temp[0]
                day = temp[1]
                if int(month) < 10:
                    month = '0' + str(month)
                if int(day) < 10:
                    day = '0' + str(day)
                key = month + '-' + day
                if key in data.keys():
                    data[key] = int(row[3]) + int(data[key])
                else:
                    data[key] = int(row[3])
    result[str(province)] = data

print(json.dumps(result, ensure_ascii=False))
